package com.zz.springboot.processor.bag.strategy;

import com.zz.springboot.anno.StrategyKeywords;
import com.zz.springboot.anno.StrategyType;
import com.zz.springboot.constant.TypeConstants;
import com.zz.springboot.exception.BizException;
import com.zz.springboot.initializer.NumDictRunner;
import com.zz.springboot.resp.enums.RespCodeEnum;
import com.zz.springboot.util.DataDealUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * 生肖解析策略
 */
@Component
@Slf4j
@StrategyType("animal")
@StrategyKeywords({"鼠", "牛", "虎", "兔", "龙", "蛇", "马", "羊", "猴", "鸡", "狗", "猪"})
//@StrategyKeywords(List.toArray(TypeConstants.animalConstant)) 这种写法是错误的，无法编译通过，因为注解属性值必须是编译时常量，不能是运行时才能确定的值
public class BagAnimalsStrategy implements BagStrategy {
    @Override
    public List<Integer> parseNum(String key) {
        return NumDictRunner.getAnimal_Map().get(key);
    }

    @Override
    public List<String> appendList(String data, Float money) {
        List<String> dataList = new ArrayList<>();
        float singleMoney=0;

        for (int i = 0; i < data.length(); i++) {
            String animal = String.valueOf(data.charAt(i));
            if (TypeConstants.animalConstant.contains(animal)) {
                // 2）定位号码
                List<Integer> nums = parseNum(animal);
                //3）纳入集合
                if (!(data.contains("各") || data.contains("每个"))){
                    singleMoney=DataDealUtils.keepPoint(money/nums.size());
                }else {
                    singleMoney=money;
                }
                for (Integer num : nums) {
                    dataList.add(num + ":" + singleMoney);
                }
            }
        }

        return dataList;
    }

    @Override
    public String getKey(String data) {
        return "";
    }
}
